package base.thread_JUC2.chapter03.demo06;

/**
 * 并发阶段任务中的阶段切换
 */
public class TestCase {
    public static void main(String[] args) {
//        MyPhaser phaser = new MyPhaser(5);
        MyPhaser phaser = new MyPhaser();

        Student[] students = new Student[5];
        for (int i = 0; i < students.length; i++) {
            students[i] = new Student(phaser);
            // 因为在创建 Phaser时未指定个数,这里需要手动注册进Phaser
            // 创建5个学生，并在phaser中注册他们
            phaser.register();
        }

        Thread[] threads = new Thread[students.length];
        for (int i = 0; i < students.length; i++) {
            threads[i] = new Thread(students[i], "学生" + i);
            threads[i].start();
        }

        for (Thread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.printf("Main: The phaser has finished: %s.\n",phaser.isTerminated());
    }
}
